function getById(_sId)

{
	return document.getElementById(_sId);
}

var dragData;

var draging;

var backData;

function moveDiv(event, _sId)

{

	var oObj = getById(_sId);

	draging = true;

	oObj.onmousemove = mousemove;

	oObj.onmouseup = mouseup;

	var oEvent = window.event ? window.event : event;

	dragData = {
		x : oEvent.clientX,
		y : oEvent.clientY
	};

	backData = {
		x : parseInt(oObj.style.top),
		y : parseInt(oObj.style.left)
	}

	function mousemove(event)

	{

		if (!draging)

			return;

		var oEvent = window.event ? window.event : event;

		var iLeft = oEvent.clientX - dragData["x"] + parseInt(oObj.style.left);

		var iTop = oEvent.clientY - dragData["y"] + parseInt(oObj.style.top);

		oObj.style.left = iLeft + 'px';

		oObj.style.top = iTop + 'px';

		dragData = {
			x : oEvent.clientX,
			y : oEvent.clientY
		};

	}

	function mouseup(event)

	{

		draging = false;

		var oEvent = window.event ? window.event : event;

		oObj.onmousemove = null;

		oObj.onmouseup = null;

		if (oEvent.clientX < 1 || oEvent.clientY < 1)

		{

			oObj.style.left = backData.y + 'px';

			oObj.style.top = backData.x + 'px';

		}

	}

}

function closeDiv(_sID)

{

	var oObj = getById(_sID);

	var overlay = getById("overlay");

	if (overlay != null)

	{

		document.body.removeChild(overlay);

	}

	oObj.style.display = "none";

}

function showDiv(_sID, event, width, height) {
	var arrySize = getPageSize();
	var oObj = getById(_sID);
	// 创建一个DIV,改名为 overlay 这个是透明的层
	oDiv = document.createElement("div");
	oDiv.id = "overlay";
	document.body.appendChild(oDiv);
	var overlay = getById("overlay");
	overlay.style.height = arrySize[1];
	overlay.style.width = arrySize[0];
	if (event == null) {
		if (oObj.style.left == "" || oObj.style.left == '0') {
			oObj.style.left = (arrySize[0] / 2 - width / 2) + 'px';
		}
		if (oObj.style.top == "" || oObj.style.left == '0') {
			oObj.style.top = (arrySize[1] / 2 - height / 2) + 'px';
		}
	} else {
		var iEvent = window.event ? window.event : event;
		oObj.style.left = (arrySize[0] / 2 - width / 2) + 'px'; // iEvent.clientX;
		oObj.style.top = (arrySize[1] / 2 - height / 2) + 'px';// iEvent.clientY;
	}
	overlay.style.display = "block";
	oObj.style.display = "block";
	overlay.style.zindex = oObj.style.zindex - 1;
}

// 取得页面大小
function getPageSize() {

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // all
		// but
		// Explorer
		// Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla
		// and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) { // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement
			&& document.documentElement.clientHeight) { // Explorer 6 Strict
		// Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if (yScroll < windowHeight) {
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if (xScroll < windowWidth) {
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
	return arrayPageSize;
}
